import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { url } from 'inspector';

@Injectable({
  providedIn: 'root'
})
export class ReportService {

  constructor(
    private http: HttpClient
  ) { }

  // 获取 表码
  getMeterNo(): Observable<any>{
    const url = '/api/gsxmcp/cs/sr/v1.0/report/usageInfo';
    return this.http.get(url);
  }

  // 提交
  submitReport(params: any): Observable<any>{
    const url = '/api/gsxmcp/cs/sr/v1.0/report/add';
    return this.http.post(url, params);
  }

  // 提交 临时接口
  submitReport2(params: any): Observable<any>{
    const url = '/api/gsxmcp/cf/mg/v1.0/funcData/selfPower';
    return this.http.post(url, params);
  }

  // 获取 列表 | 同时也是 详情
  getReportList(pageNumber = 1, pageSize = 5): Observable<any>{
    const url = "/api/gsxmcp/cs/sr/v1.0/report/page";
    let args = {
      pageNumber,
      pageSize
    }
    let params = new HttpParams({ fromObject: args });  // queryString: qs
    // return this.http.get( url, { params }).pipe(map((res: {resultList: any[] }) => {
    //   let resultList = res.resultList;
    //   resultList.forEach((item) => {
    //     delete item.reportNo;
    //     delete item.month;
    //     delete item.reportTime;
    //     delete item.state;
    //   })
    //   return resultList;
    // }));
    return this.http.get( url, { params })
  }

  getReportDetailById(id: any): Observable<any>{
    let url = `/api/gsxmcp/cs/sr/v1.0/report/detail/${id}`;

    return this.http.get(url);
  }

}
